package com.liaoban.app.ui.anchor;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

import com.liaoban.app.R;
import com.liaoban.app.adapter.GlideImageLoader;
import com.liaoban.app.adapter.MyGlideImageLoader;
import com.liaoban.app.constants.ExtraParam;
import com.liaoban.app.ui.base.BaseActivity;
import com.liaoban.app.widget.MyBanner;

import java.io.Serializable;
import java.util.List;

import butterknife.BindView;

public class ImgBannerActivity extends BaseActivity {
    @BindView(R.id.banner)
    MyBanner banner;

    private int mPos;
    private List<String> mImgs;

    public static Intent newIntent(Context context, List<String> imgs, int pos) {
        Intent intent = new Intent(context, ImgBannerActivity.class);
        intent.putExtra(ExtraParam.POSITION, pos);
        intent.putExtra(ExtraParam.LIST, (Serializable) imgs);
        return intent;
    }

    @Override
    protected int getLayoutResID() {
        //去除title
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        //去掉Activity上面的状态栏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        return R.layout.activity_img_banner;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        initData();
        initBanner();
    }

    private void initData() {
        mPos = getIntent().getIntExtra(ExtraParam.POSITION, 0);
        mImgs = (List<String>) getIntent().getSerializableExtra(ExtraParam.LIST);
    }

    /**
     * 初始化轮播图
     */
    private void initBanner() {
        banner.setOnBannerListener(position -> finish());
        banner.setImages(mImgs).setImageLoader(new MyGlideImageLoader()).start(mPos + 1);
    }
}
